<template>
  <div>
    <div class="tabbar">
      <div
        v-for="(item, index) in items"
        :key="index"
        class="item"
        :class="{ active: index === currentActive }"
        @click="activateItem(index)"
      >
        {{ item }}
      </div>
    </div>
    <div v-if="list.length > 0">
      <el-card
        class="card"
        v-for="(item, index) in list"
        :key="index"
        style="width: 100%"
        shadow="hover"
        @mouseover="handleMouseOver(index)"
        @mouseout="handleMouseOut"
      >
        <div class="main">
          <div class="inner">
            <span class="jobname">{{ item.jobName }}</span>
            <div class="center">
              <div class="salary" v-if="item.salaryMeet === 2">
                {{ item.salaryRangeFrom }}k-{{ item.salaryRangeTo }}k
              </div>
              <div class="salary" v-else> 薪资面议 </div>
              <div class="fenge"></div>
              <div class="city">
                {{ item.jobCity.split(';').join(' ') }}
              </div>
              <div class="fenge"></div>
              <div class="edu">
                <span v-if="item.jobRequireEdu === 1">专科及以上</span>
                <span v-else-if="item.jobRequireEdu === 2">本科及以上</span>
                <span v-else-if="item.jobRequireEdu === 3">硕士及以上</span>
                <span v-else>不限</span>
              </div>
            </div>
            <div class="bottom">
              <div class="left">
                <el-avatar :size="30" :src="item.avatar" />
                <span style="margin-left: 10px">{{ item.nickName }}</span>
              </div>
              <div class="right" :style="{display: index===currentHoverIndex ? 'none' : 'block'}">
                <span style="margin-right: 24px">
                  {{ format(new Date(item.createTime), 'yyyy/MM/dd hh:mm') }}
                </span>
                <span v-if="item.jobResumeStatus === 1"> 简历待处理 </span>
                <span v-else-if="item.jobResumeStatus === 0"> 简历已查看 </span>
                <span v-else-if="item.jobResumeStatus === 2"> 简历通过初筛 </span>
                <span v-else-if="item.jobResumeStatus === 3"> 不合适 </span>
              </div>
            </div>
            <div class="detail" @click="openPDF(item.resumePath)">查看投递简历</div>
          </div>
        </div>
      </el-card>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <div class="empty" v-else>
      <img src="./none.png" alt="" />
      <div style="margin-top: 20px">暂无记录，点击我要求职，查看适合你的职位</div>
      <el-button type="primary" plain style="margin-top: 20px">我要求职</el-button>
    </div>
  </div>
  <ResumeInfoPDF ref="formRef"/>
</template>

<script setup lang="ts">
import { ref, reactive, toRefs, onMounted } from 'vue'
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import { JobResumeInfoApi, StudentJobResumeInfoVO } from '@/api/dbit/jobresumeinfo'
import { format } from 'date-fns'
import ResumeInfoPDF from './ResumeInfoPDF.vue'

const loading = ref(true) // 列表的加载中
const list = ref<StudentJobResumeInfoVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const cityView = ref('') // 城市展示
const currentHoverIndex  = ref(null) // 控制按钮的显示隐藏

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  jobName: undefined,
  userId: undefined,
  jobResumeStatus: undefined
})
const items = ['已投递', '被查看', '通过初筛', '不合适']
const currentActive = ref(0) // 默认激活第一个项

const activateItem = (index: number) => {
  currentActive.value = index
  queryParams.jobResumeStatus = index
  getList()
}

// 获取投递记录列表
const getList = async () => {
  loading.value = true
  try {
    const data = await JobResumeInfoApi.getStudentJobResumeInfoPage(queryParams)
    console.log(data)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

const handleMouseOver = (index) => {
  currentHoverIndex .value = index
}
const handleMouseOut = () => {
  currentHoverIndex .value = null
}
const formRef = ref()
const openPDF = (url) => {
  formRef.value.open(url)
}

/** 初始化 **/
onMounted(() => {
  const id = localStorage.getItem('userId')
  queryParams.userId = id
  queryParams.jobResumeStatus = 0
  getList()
})
</script>

<style scoped>
.tabbar {
  display: flex;
  width: 100%;
  height: 38px;
  padding: 20px 20px 0;
  margin-bottom: 12px;
  background-color: #fff;
}

.tabbar .item {
  margin-right: 30px;
  font-size: 16px;
  font-weight: 500;
  line-height: 16px;
  cursor: pointer;
}

.active {
  color: #7cd1ff;
}

.tabbar .item:hover {
  color: #7cd1ff;
}

.card {
  margin: 6px 0;
}

.main {
  padding: 20px 16px 0;
}

.inner {
  display: flex;
  flex-direction: column;
  height: 109px;
  position: relative;
}

.inner .jobname {
  font-size: 18px;
  font-weight: 500;
  color: rgb(51 51 51);
}

.inner .center {
  display: flex;
  height: 14px;
  margin: 16px 0;
}

.inner .center .salary {
  font-size: 14px;
  line-height: 14px;
  color: rgb(234 78 7);
}

.inner .center .fenge {
  width: 1px;
  height: 100%;
  margin: 0 12px;
  background-color: rgb(221 221 221);
}

.inner .center .city,
.inner .center .edu {
  font-size: 14px;
  line-height: 14px;
  color: rgb(153 153 153);
}

.inner .bottom {
  display: flex;
  height: 24px;
}

.inner .bottom .left {
  display: flex;
  width: 75%;
  font-size: 14px;
  line-height: 14px;
  align-items: center;
}

.inner .bottom .right {
  width: 25%;
  font-size: 14px;
  line-height: 14px;
  color: rgb(153 153 153);
}

.empty {
  height: 288px;
  padding: 100px 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: rgb(68, 68, 68);
  font-size: 14px;
  line-height: 14px;
}
.empty img {
  width: 200px;
  height: 200px;
}
.card:hover{
  background-color: #f8f8f8;
}
.card:hover .detail{
  display: block;
}
.detail {
  display: none;
  position: absolute;
  font-size: 14px;
  line-height: 14px;
  transform: translateY(-27px);
  color: #409eff;
  padding: 9px 16px;
  border: 1px solid #409eff;
  border-radius: 8px;
  top: 50%;
  right: 0;
}
.detail:hover{
  cursor: pointer;
  background-color: #409eff;
  color: #fff;
}
</style>
